package com.kaisa.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaisa.activity.R;
import com.kaisa.activity.bean.SortBean;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2015/12/13.
 * sortfragment适配器
 */
public class SortAdapter extends AppBaseAdapter<SortBean>{

    public SortAdapter(List<SortBean> list, Context context) {
        super(list, context);
        inflater = LayoutInflater.from(context);
    }


    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_list_sort,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //映射数据
        holder.img.setBackgroundResource(list.get(position).getImgId());
        holder.title.setText(list.get(position).getTitle());
        holder.content.setText(list.get(position).getContent());
        return convertView;
    }

    public static class ViewHolder extends BaseViewHolder{
        @ViewInject(R.id.item_sort_img)
        private ImageView img;
        @ViewInject(R.id.item_sort_title)
        private TextView title;
        @ViewInject(R.id.item_sort_content)
        private TextView content;

        public ViewHolder(View convertView) {
            super(convertView);
            x.view().inject(this,convertView);
        }
    }
}
